select ' INSERT INTO REFERENCEID(MODULENAME,BRANCH,REFERENCEID) VALUES (' 
+ '''' + ISNULL(MODULENAME,'') 
+ ''',''' + ISNULL(BRANCH,'')
+ ''',' + ISNULL(str(REFERENCEID,4),'Null')
+ ')' 
from REFERENCEID ORDER BY REFERENCEIDKEY 

